-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed UDP sendto if IP version not match #10834
Conversation
This looks good. You managed to find the solution without touching the LwIP internals. |
features/lwipstack/LWIPStack.cpp
Outdated
|
||
nsapi_addr_t addr = address.get_addr(); | ||
if (!convert_mbed_addr_to_lwip(&ip_addr, &addr)) { | ||
return NSAPI_ERROR_PARAMETER; | ||
} | ||
|
||
convert_lwip_addr_to_mbed(&interface_addr, get_ip_addr(true, &default_interface->netif)); | ||
if(addr.version != interface_addr.version){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
astyle failure fix needed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
features/lwipstack/LWIPStack.cpp
Outdated
|
||
nsapi_addr_t addr = address.get_addr(); | ||
if (!convert_mbed_addr_to_lwip(&ip_addr, &addr)) { | ||
return NSAPI_ERROR_PARAMETER; | ||
} | ||
|
||
convert_lwip_addr_to_mbed(&interface_addr, get_ip_addr(true, &default_interface->netif)); | ||
if(addr.version != interface_addr.version){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work in dual stack case when you have both addresses? get_ip_addr
will return the preferred address (defined with lwip.ip-ver-pref
configuration), but the application uses the other address version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is both IP4 and IP6 on netif then IP_VERSION_PREF must be properly set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to get rid of prefered dependency, how about something like this:
lwip_tools.cpp:
bool LWIP::dualstack_enabled()
{
#if LWIP_IPV4 && LWIP_IPV6
if (get_ipv4_addr(netif) && get_ipv6_addr(netif)) {
return true;
}
#endif
return false;
}
and then in version check first check that dualstack is not on:
if (!dualstack_enabled() && addr.version != interface_addr.version) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified
6fd059e
to
5e1cc17
Compare
features/lwipstack/LWIPStack.cpp
Outdated
|
||
nsapi_addr_t addr = address.get_addr(); | ||
if (!convert_mbed_addr_to_lwip(&ip_addr, &addr)) { | ||
return NSAPI_ERROR_PARAMETER; | ||
} | ||
|
||
convert_lwip_addr_to_mbed(&interface_addr, get_ip_addr(true, &default_interface->netif)); | ||
if (addr.version != interface_addr.version) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dual-mode is possible - that fails sending to IPv4 if you're dual IPv4 and IPv6 with IPv6 preferred.
Not to mention the issue of multiple potential interfaces - that blocks IPv6 on the IPv6 interface if your default is IPv4.
To get a good answer here, I think you'd have to get the error from lwIP. Seems like lwIP is probably generating an error internally, but it gets lost. netconn_send
doesn't extract the err
value from the msg
that netconn_do_send
fills in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed dualstack issue as Kimmo suggested.
Checked that if both ip4/6 enabled netconn returns ERR_OK because ip_route always finds the netif.
5e1cc17
to
82ed294
Compare
@kjbracey-arm please review updates |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restating the logic here, to make sure I've got it right:
"If the default interface doesn't have both IPv4 and IPv6 addresses, check to see if this address matches the type of the preferred (and hence only) IP address of the default interface."
Still a bit nervous that this is fragile. What if your default interface is IPv4 only, but you've got a IPv6 interface?
Maybe with default routing that setup wouldn't work anyway - traffic always goes to the default, but if you've done a NSAPI_BIND_TO_DEVICE
, you do need to look at the bound interface, right, not the default one?
Kevin, your proposal has sense. However it is a kind of core LWIP functionality improvement. |
My main concern is that this can break multihoming, by not looking at the interface the socket is bound to. Not sure you need to necessarily change lwIP core for that - if you can record the bound interface in the glue layers, that might be sufficient. I believe more complex multi-interface routing is not supported, but locking sockets to interfaces is supposed to work. If you're not currently testing split IPv4/IPv6 multihoming, I guess you get away with it for now, but I'd want an immediate issue for that limitation created if you merge this. |
Currently if the socket is bound to interface, ip_route uses that netif instead of default one according to multihoming. But socket is bound just to interface name regardless of ip version. NSAPI_BIND_TO_DEVICE can bind netif v4 or v6 according to the user requirements. In case of dual stack and each netif has only one ip version there is no issue with preferred IP. Im using "get_ip_addr" with "true" parameter so if preffered ip not exist it returns not preffered. The problem exist if dual stack is enabled and one netif has both ip4 and ip6. This case wasn't tested during multihoming launch. |
I think the correct version is relatively simple - arguably simpler than this PR. Detail needs to be filled in, but structurally:
This is relatively cautious - only blocking the call when it has a good idea what's going on. If it doesn't recognise the address version or know what the default interface is it will proceed. Maybe that could be tightened, depending on what you want. Note that as |
568ae20
to
f8cd118
Compare
Applied |
netif_ = &default_interface->netif; | ||
} | ||
if (netif_) { | ||
if ((addr.version == NSAPI_IPv4 && !get_ipv4_addr(netif_)) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, I didn't consider V4/V6-only compilation - it looks like these get_ipvx_addr
aren't defined if LWIP_IPVX
isn't enabled. You should probably fiddle them to have them defined and return constant NULL in that case - will be neater than adding ifdefs here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed get_ipvx_addr LWIP_IPV4/6
…on differ from destination adress IP version
f8cd118
to
b272c5f
Compare
@kjbracey-arm could you please re-review after the recent change? |
CI started |
Test run: FAILEDSummary: 6 of 7 test jobs failed Failed test jobs:
|
Aborted the job unfortunately as we have to reschedule one possibly rc4 PR. |
Ci restarted |
Test run: FAILEDSummary: 1 of 11 test jobs failed Failed test jobs:
|
Description
Fixed LWIPStack class socket_sendto member to fail if interface IP4/6 version differ from destination adress IP version
Pull request type
Reviewers
@SeppoTakalo
@kivaisan
Release Notes